package com.pass.three;

import java.io.IOException;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import com.utils.ConstantVariables;

/**
 * Pass Three Mapper emits all edges involving intersection points to every
 * reducer, as well as the Nodes (in the form of Edges) to respective reducer.
 */
public class PassThreeMapper extends
		Mapper<LongWritable, Text, IntWritable, Text> {
	@Override
	protected void map(LongWritable key, Text value, Context context)
			throws IOException, InterruptedException {
		String[] keyVal;
		keyVal = value.toString().split("\\t");
		if (key.get() == -1) {
			for (int i = 0; i < ConstantVariables.M[ConstantVariables.testNumber]; i++) {
				context.write(new IntWritable(i), new Text(keyVal[1]));
			}
		} else {
			context.write(new IntWritable(Integer.parseInt(keyVal[0])),
					new Text(keyVal[1]));
		}
	}
}
